using System;
using System.Data;
using NHibernate;
using NHibernate.SqlTypes;
using NHibernate.UserTypes;
using Tools.Common.ServiceLocator;

namespace Webshop20.Infrastructure.Persistence.NH.UserTypes
{
    public class ConstraintSetUserType : IUserType
    {
        public bool Equals(object x, object y)
        {
            if (x == null)
                return false;
            return x.Equals(y);
        }

        public int GetHashCode(object x)
        {
            return x.GetHashCode();
        }

        public object NullSafeGet(IDataReader rs, string[] names, object owner)
        {
            string name = NHibernateUtil.String.NullSafeGet(rs, names[0]) as string;
            string[] typInfos = name.Split('_');
            return ServiceLocator.Current.Resolve(Type.GetType(typInfos[0]), typInfos[1]);
        }

        public void NullSafeSet(IDbCommand cmd, object value, int index)
        {
            string name = value.GetType().Name;
            NHibernateUtil.String.NullSafeSet(cmd, name, index);
        }

        public object DeepCopy(object value)
        {
            throw new System.NotImplementedException();
        }

        public object Replace(object original, object target, object owner)
        {
            throw new System.NotImplementedException();
        }

        public object Assemble(object cached, object owner)
        {
            throw new System.NotImplementedException();
        }

        public object Disassemble(object value)
        {
            throw new System.NotImplementedException();
        }

        public SqlType[] SqlTypes
        {
            get { throw new System.NotImplementedException(); }
        }

        public Type ReturnedType
        {
            get { throw new System.NotImplementedException(); }
        }

        public bool IsMutable
        {
            get { throw new System.NotImplementedException(); }
        }
    }
}